using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace ASP_TF2LogParser.Admin
{
    public partial class DeleteLogFile : System.Web.UI.Page
    {
        protected void Page_Load( object sender, EventArgs e )
        {
            DeleteResult.Text = string.Empty;

            if ( !Page.IsPostBack )
            {
                LoadData();
            }

            if ( Request.QueryString[ "result" ] == "success" )
            {
                DeleteResult.Text = "Log File Deleted Successfully";
            }
            else if ( Request.QueryString[ "result" ] == "failure" )
            {
             
                DeleteResult.Text = "Log File Delete Failed, Please Contact the Developer with the name of the log file you were trying to delete.";
            }
            else
            {
                DeleteResult.Text = string.Empty;
            }
        }

        private void LoadData()
        {
            LogParser.DA.DataObjects.LogFilesDS.LogFilesDataTable dt = LogParser.DA.LogFileModel.GetLogList();

            LogFileNameListcbo.DataSource = dt;
            LogFileNameListcbo.DataTextField = "LogName";
            LogFileNameListcbo.DataValueField = "LogId";
            LogFileNameListcbo.DataBind();
        }

        protected void DeleteButton_Click( object sender, EventArgs e )
        {
            int logId = Convert.ToInt32( LogFileNameListcbo.SelectedItem.Value );

            bool result = LogParser.DA.LogFileModel.DeleteAllDataByLogId( logId );

            if ( result )
            {
                Response.Redirect( "DeleteLogFile.aspx?result=success" );
            }
            else
            {
                Response.Redirect( "DeleteLogFile.aspx?result=failure" );
            }
        }
    }
}
